package com.amit.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@WebServlet(name="addeng",urlPatterns={"/addenquiry.jlc"})
public class AddEnquiryServlet  extends HttpServlet
{
	
public AddEnquiryServlet()
	{
		System.out.println("default");
	}
	@Override
	public void init(ServletConfig config) {
		
		System.out.println("init()");
		
	}
	@Override
	public void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		//1.collect the data
		
		String fn=request.getParameter("fname");
		String em=request.getParameter("email");
		String ph=request.getParameter("phone");
		String ge=request.getParameter("gender");
		String ti=request.getParameter("timings");
		String co=request.getParameter("course");
		String cous[]=request.getParameterValues("course");
		String re=request.getParameter("remarks");
		
		//2.process 
		
		String msg="Your Enquiry Has Been added Successfully";
		
		System.out.println("Full name:"+fn);
		System.out.println("Email ID:"+em);
		System.out.println("Phone No:"+ph);
		System.out.println("Gender:"+ge);
		System.out.println("Timings:"+ti);
		System.out.println("Course:"+co);
		System.out.println("All Courses");
		
		for(String i:cous)
		{
			System.out.println(i);
		}
		
		 System.out.println("Remarks:"+re);
		 
		 //3.send response
		 
		 response.setContentType("text/html");
		 PrintWriter out=response.getWriter();
		 
		 out.println("<h1><center>Java Learning Center</center></h1>");
		 out.println("<h1><center>"+msg+"<center></h1>");
		 out.println("<h1>Full name:</h1>"+fn);
		 out.println("<h1>Email ID:</h1>"+em);
		 out.println("<h1>Phone No:</h1>"+ph);
		 out.println("<h1>Gender:</h1>"+ge);
		 out.println("<h1>Timings:</h1>"+ti);
		 out.println("<h1>Course:</h1>"+co);
		 out.println("<h1>All Courses:</h1>");
		 
		 for(String c:cous)
		 {
			 out.println(c);
		 }
		 
		out.println("<h1> Remarks"+re);
		
	
	}
	
	@Override
	public void destroy() {
		
	System.out.println("destroy()");
	
	}
	

}
